package com.gxa.modules.service.operationsservice.impl;

import com.gxa.common.R;
import com.gxa.modules.mapper.operationsmapper.ClientMapper;
import com.gxa.modules.pojo.Client;
import com.gxa.modules.service.operationsservice.ClientService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class ClientImplService implements ClientService {
    @Resource
    private ClientMapper clientMapper;


    @Override
    public R selectAllClientForPage(int page, int size) {
        //分页
        int index=(page-1)*size;
        R r = new R();
        HashMap<Object, Object> map = new HashMap<>();
        List<Client> clients = clientMapper.selectAllClientForPage(index,size);
        map.put("data",clients);
        int res = clientMapper.selectAllClientForPagesum( page,size);
        map.put("count",res);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);
        }

        return r;
    }

    @Override
    public R selectAllClient(int page, int size, String clientName, String intentionLevel, String clientLevel,
                             String followUpStatus) {
        int index=(page-1)*size;
        R r = new R();
        HashMap<Object, Object> map = new HashMap<>();
        List<Client> clients = clientMapper.selectAllClient(index,size,clientName, intentionLevel,  clientLevel,
               followUpStatus);

        map.put("data",clients);


        int res = clientMapper.selectAllClientsum( clientName, intentionLevel,  clientLevel,
                followUpStatus);
        map.put("count",res);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);
        }


        return r;
    }

    @Override
    public R insertClient(Client client) {
        R r = new R();
        System.out.println(client);
        int res = clientMapper.insertClient(client);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    @Override
    public R deleteClientById(String id) {
        return null;
    }

}
